package com.zim.ta_service.support;

import cn.hutool.core.util.ObjectUtil;

/**
 * author: alabimofa <br>
 * date: 2021/10/21 20:19 <br>
 */
public class ExceptionUtil {

	/**
	 * 获取异常类名
	 */
	public static String getExceptionClassName(Throwable e) {
		if (ObjectUtil.isNull(e)) {
			return "";
		}

		//获取所有堆栈信息
		StackTraceElement[] stackTraceElements = e.getStackTrace();

		//默认的异常类全路径为第一条异常堆栈信息的
		String exceptionClassTotalName = stackTraceElements[0].toString();
		for (StackTraceElement stackTraceElement : stackTraceElements) {
			if (stackTraceElement.toString().contains("com.delai")) {
				exceptionClassTotalName = stackTraceElement.toString();
				break;
			}
		}
		return exceptionClassTotalName;
	}
}
